package com.gopay.common.cps.dao.fund.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.fund.FundCpsMainDao;
import com.gopay.common.domain.cps.CpsGenMainOrder;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BindCardDAOImpl.java
 * @author baiyunpeng
 * @2016年7月4日 上午10:27:00  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("fundCpsMainDaoExt")
public class FundCpsMainDaoImpl extends BaseDAOImpl<CpsGenMainOrder,Serializable> implements FundCpsMainDao {
    @Override
    public List<CpsGenMainOrder> getCpsGenMainOrderByRemaker2(String remaker2){
        if(remaker2!=null){

            StringBuffer sql = new StringBuffer("");
            sql.append("from CpsGenMainOrder where remark2=:merRemark2");
            Map<String,Object> map = new HashMap<>();
            map.put("merRemark2",remaker2);
            List<CpsGenMainOrder> byHql = findByHql(sql.toString(), map);
            if(byHql!=null && byHql.size()>0){
                return byHql;
            }
        }
        return null;
    }

    @Override
   public CpsGenMainOrder getMainOrderByReleveGopayId(String releveGopayId){
       if(releveGopayId!=null){

           StringBuffer sql = new StringBuffer("");
           sql.append("from CpsGenMainOrder where gopayOrderId=:releveGopayId");
           Map<String,Object> map = new HashMap<>();
           map.put("releveGopayId",releveGopayId);
           List<CpsGenMainOrder> byHql = findByHql(sql.toString(), map);
           if(byHql!=null && byHql.size()>0){
               return byHql.get(0);
           }
       }
       return null;
    }

    @Override
    public CpsGenMainOrder getCpsGenMainOrder(String gopayId){
        if(gopayId!=null){

            StringBuffer sql = new StringBuffer("");
            sql.append("from CpsGenMainOrder where gopayOrderId=:gopayId");
            Map<String,Object> map = new HashMap<>();
            map.put("gopayId",gopayId);
            List<CpsGenMainOrder> byHql = findByHql(sql.toString(), map);
            if(byHql!=null && byHql.size()>0){
                return byHql.get(0);
            }
        }
        return null;
    }

    @Override
    public List<CpsGenMainOrder> getCpsGenMainOrder4Settle(String gopayOrderId) {
        if (StringUtils.isNotEmpty(gopayOrderId)) {
            StringBuffer sql = new StringBuffer("From CpsGenMainOrder where remark2=:gopayOrderId and txnStaCd=30000 ");
            Map<String, Object> map = new HashMap<>();
            map.put("gopayOrderId", gopayOrderId);
            sql.append("and gopayIntTxnCd in('02012','02014','02015','02020','02021')");
            List<CpsGenMainOrder> cpsGenMainOrderList = findByHql(sql.toString(), map);
            return cpsGenMainOrderList;
        }
        return null;
    }
}
